import os
import re
import shutil

import numpy as np
import scipy.io as scio
import pandas as pd

from datetime import datetime
from tqdm import tqdm

def process_radardata(allradardatafilepathfolder,allradardatafilepath,chirp):
    """
    function: after "read_mmWave_data(6843).m" processed, this function is save each one's capture start time
    args: allradardatafilepathfolder:the root path of radar data
          allradardatafilepath: one radar data file name
          chirp: the mmWave radar param chirp loops e.g. 64 
    
    return: framefilepath the named with "allradardatafilepath+'_frame.npy'",
            which save radar capture start time 

    e.g.
    a='E:/HARDATASET/RADAR_TRANSFER_STATION/'
    b=os.listdir(a)
    b = sorted(b, key=lambda x: int(re.findall('\d+', x)[0]))
    # print(allradardatafilepathlist)
    for i in tqdm(range(len(b))):
        process_radardata(a,b[i],64)
    """
    Capture_start_time = datetime.strptime(allradardatafilepath, 
                                           '%Y%m%d%H%M%S')

    radardatalen=480000
    onefps=300/(radardatalen/chirp)
    framefilepath=os.path.join(allradardatafilepathfolder,
                               allradardatafilepath,
                               allradardatafilepath+'_frame.npy')


    framelist=[]

    for i in range(int(radardatalen/chirp)):
        framelist.append(i*onefps+Capture_start_time.timestamp())

    framearray=np.array(framelist)
    np.save(framefilepath,framearray)

    